package com.nike.amoeba.bean

import androidx.room.Database
import androidx.room.Room
import androidx.room.RoomDatabase
import com.nike.amoeba.bean.dao.AssetDao
import com.nike.amoeba.bean.dao.ConfigDao
import com.nike.amoeba.bean.dao.ExistEpcDao
import com.nike.amoeba.bean.dao.MainDrawerDao
import com.nike.amoeba.bean.dao.MainDrawerParentDao
import com.nike.amoeba.bean.dao.TaskAssetDao
import com.nike.amoeba.bean.dao.StockEpcDao
import com.nike.amoeba.bean.dao.TaskStockListDao
import com.nike.amoeba.bean.dao.TaskStockDao
import com.nike.amoeba.bean.dao.UploadOrderDao
import com.nike.amoeba.bean.dao.UploadOrderListDao
import com.nike.amoeba.bean.dao.StockManageEpcDao
import com.nike.amoeba.bean.dao.StockManageListDao
import com.nike.amoeba.bean.db.AssetBean
import com.nike.amoeba.bean.db.ConfigBean
import com.nike.amoeba.bean.db.ExistEpcBean
import com.nike.amoeba.bean.db.MainDrawerBean
import com.nike.amoeba.bean.db.MainDrawerParentBean
import com.nike.amoeba.bean.db.TaskAssetBean
import com.nike.amoeba.bean.db.StockEpcBean
import com.nike.amoeba.bean.db.StockManageEpcBean
import com.nike.amoeba.bean.db.TaskStockListBean
import com.nike.amoeba.bean.db.TaskStockBean
import com.nike.amoeba.bean.db.UploadOrderBean
import com.nike.amoeba.bean.db.UploadOrderListBean
import com.nike.amoeba.bean.db.StockManageListBean
import com.nike.amoeba.mar.MyApplication


/**
 * @Author nike
 * @Date 2023/7/11 18:00
 * @Description
 */
@Database(entities = [
    TaskAssetBean::class,
    AssetBean::class,
    UploadOrderBean::class,
    ConfigBean::class,
    UploadOrderListBean::class,
    StockManageListBean::class,
    ExistEpcBean::class,
    TaskStockBean::class,
    TaskStockListBean::class,
    StockEpcBean::class,
    MainDrawerBean::class,
    MainDrawerParentBean::class,
    StockManageEpcBean::class,
], version = 1, exportSchema = false)
abstract class AppRoomDataBase : RoomDatabase() {

    abstract fun getTaskAssetDao(): TaskAssetDao

    abstract fun getAssetDao(): AssetDao

    abstract fun getUploadOrderDao(): UploadOrderDao

    abstract fun getUploadOrderListDao(): UploadOrderListDao

    abstract fun getConfigDao(): ConfigDao
    abstract fun getStockManageEpcDao(): StockManageEpcDao
    abstract fun getStockListDao(): StockManageListDao
    abstract fun getExistEpcDao(): ExistEpcDao
    abstract fun getTaskStockDao(): TaskStockDao
    abstract fun getTaskStockListDao(): TaskStockListDao
    abstract fun getStockEpcDao(): StockEpcDao
    abstract fun getMainDrawerDao(): MainDrawerDao
    abstract fun getMainDrawerParentDao(): MainDrawerParentDao

    companion object {

        @Volatile
        private var databaseInstance: AppRoomDataBase? = null

        @Synchronized
        @JvmStatic
        fun get(): AppRoomDataBase {
            if (databaseInstance == null) {
                databaseInstance = Room.databaseBuilder(
                    MyApplication.get(),
                    AppRoomDataBase::class.java,
                    "amoeba_sql_app.db"
                )
                    /*.addMigrations(
                        object : Migration(1, 2) {
                        override fun migrate(database: SupportSQLiteDatabase) {
                            // 执行从旧版本升级到新版本的 SQL 语句
//                            database.execSQL("CREATE TABLE IF NOT EXISTS 'OrderBean' (id INTEGER PRIMARY KEY, description TEXT)")
                        }
                    })*/
//                    .allowMainThreadQueries()//允许在主线程操作数据库，一般不推荐；设置这个后主线程调用增删改查不会报错，否则会报错
//                    .openHelperFactory(factory)
                    .build()
            }
            return databaseInstance!!
        }

    }

}